<template>
  <h1>循环指令</h1>
  <ul>
    <li v-for="item in 5">{{item}}</li>
  </ul>
  <ul>
    <li v-for="p in productArr">{{p.title}}</li>
  </ul>
  <table border="1px">
    <tr>
      <th>序号</th>
      <th>标题</th>
      <th>价格</th>
      <th>库存</th>
      <th>操作</th>
    </tr>
    <tr v-for="(item,index) in productArr">
      <td>{{index+1}}</td>
      <td>{{item.title}}</td>
      <td>{{item.price}}</td>
      <td>{{item.num}}</td>
      <td><button @click="del(index)">删除</button></td>
    </tr>
  </table>
</template>

<script setup>
  import {ref} from 'vue';
  const productArr = ref([
      {title:'苹果',price:50,num:10},
      {title:"山竹",price:520,num:100},
      {title:"冬枣",price:10,num:1000},
      {title:"火龙果",price:40,num:610},
      {title:"芒果",price:20,num:200}
  ]);
  const del = (index)=>{
    if(confirm('您确认要删除吗？')){
      productArr.value.splice(index,1);
    }
  }
</script>



<style scoped>

</style>